<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="author" content="ISUX">
    <meta name="layout" content="main_mobile">
    <meta name="format-detection" content="telephone=no"/>
    <meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes"/>
    <meta name="apple-mobile-web-app-status-bar-style" content="black"/>

    <link rel="stylesheet" type="text/css" href="../frozen/css/frozen.css">
    <link rel="stylesheet" type="text/css" href="../css/default.css">

    <title>个人中心详情</title>
    <link rel="stylesheet" type="text/css" href="../css/user_center.css">
    <link rel="stylesheet" type="text/css" href="../venobox/venobox.css" media="screen" />
    <style type="text/css">
    .ui-btn.disabled, .disabled.ui-btn-lg, .disabled.ui-btn-s, .ui-btn:disabled, .ui-btn-lg:disabled, .ui-btn-s:disabled{
      background-color: #fdfdfd;
      color:#cacccd;
    }
    </style>
</head>
<body>
    <section class="ui-container">
        <input type="hidden" value="" id="project">
        <ul class="ui-tiled ui-info-tiled ui-border-tb">
            <li>
                <div class="num"><em>${projectsTotal}</em>个</div>
                <div>发起项目</div>
            </li>
            <li>
                <div class="num"><em>${donatesTotalcount }</em>份</div>
                <div>收获爱心</div>
            </li>
            <li>
                <div class="num"><em><g:formatNumber number="${totaldonateMoney }" format="0.00"/></em>元</div>
                <div>共筹善款</div>
            </li>
        </ul>

        <div class="ui-card-module ui-border-tb">
            <h4 class="ui-border-b">发起记录(${projectsTotal})</h4>

            <ul class="p-list" id="myproject">
            </ul>
             
        </div>

         <div class="ui-line-more" id="more">
             <p  id='week'>加载完成</p>
        </div>
        <div class="ui-dialog" id="execute-dialog">
	    <div class="ui-dialog-cnt">
	    	<div class="ui-dialog-bd">
		    	<div>
		    		<h4>拨款申请</h4><div></div>
		    	</div>
	    	</div>
    	<div class="ui-dialog-ft ui-btn-group">
	    		<button type="button" data-role="button" class="select" id="dialogButton-submit" onclick="apllication('execute-dialog');">确认</button>
	    		<button type="button" data-role="button" id="dialogButton-cancel" onclick="closeDialog('execute-dialog')">取消</button>
	    </div>
	    </div>
    </div>
    
    <div class="ui-dialog" id="expried-dialog">
    	<div class="ui-dialog-cnt">
    		<div class="ui-dialog-bd">
    			<div>
    			<h4>重要提示</h4>
    			    <div class="ui-form-item ui-form-item-radio ">
			            <label class="ui-radio" for="radio">
			                <input id="yan" type="radio" checked name="radio">
			            </label>
			            <p>申请延期</p>
			        </div>
			        <div class="ui-form-item ui-form-item-radio ">
			            <label class="ui-radio" for="radio">
			                <input id="bo" type="radio"   name="radio">
			            </label>
			            <p>申请拨款</p>
			        </div>
    			    <div style="text-align: center;margin-top: 15px"></div>
    			</div>
    		</div>
	    	<div class="ui-dialog-ft ui-btn-group">
	    		<button type="button" data-role="button" class="select" id="dialogButton-submit" onclick="expriedClick('expried-dialog');">确认</button>
	    		<button type="button" data-role="button" id="dialogButton-cancel" onclick="closeDialog('expried-dialog')">取消</button>
	    	</div>
    	</div>
    </div>
    </section>

    <script src="../frozen/lib/zeptojs/zepto.min.js"></script>
    <script src="../frozen/js/frozen.js"></script>
    
    <script>
	var userid = ${user.id}
    var finalOffset=20
 	var offset = 0
 	ajaxRead();  
    function ajaxRead(){
        var html="";  
    	$.ajax({  
            type:'get',  
            dataType:'json',
            url:'/scfire/user/userMyProjectDetail?format=json&offset='+ offset,  		           
            beforeSend:function(){console.log('loading...');$("#week").html('加载中...');},  
            success:function(data){
	         
          	  $.each(data,function(i,item){
          		offset++
          		     html+="<li>"
            		 html+="<a href='/scfire/project/projectDetail?projectid="+item.id+"' >"
            		 html+="<div class='top' style='background-image:url(/scfire/project/imgRead?img="+item.img+")'>"
            		 html+="<div class='h3-box'><h3>"+item.name+"</h3></div>"
            		 html+="<div class='ui-progress'>"
            		 html+="<span style='width:"+item.progress+"%'></span>"
            		 html+="</div>"
                   if(item.verified=='draft'){
                  	 html+="<div class='status'>草稿</div>"
                   }else if(item.verified=='wait'){
                  	 html+="<div class='status'>审核中</div>"
                   }else if(item.verified=='modify'){
                  	 html+="<div class='status'>待编辑</div>"
                   }else if(item.verified=='refuse'){
                  	 html+="<div class='status'>不通过</div>"
                   }else if(item.verified=='pass'){
                  	 html+="<div class='status'>募集中</div>"
                   }else if(item.verified=='execute'||item.verified=='expired'){
                  	 html+="<div class='status yellow'>已筹完</div>"
                   }else if(item.verified=='over'){
                  	 html+="<div class='status yellow'>已结项</div>"
                   }else if(item.verified=='doing'){
                  	 html+="<div class='status yellow'>执行中</div>"
                   } 
            		 html+="</div>"
            		 html+="<div class='bottom'>"
            		 html+="<div class='infos'>"
   	          		 html+="<div class='infos-l'>共<span class='num'>"+item.donatenum+"</span>份爱心</div>"
   	          		 html+="<div class='infos-r'>已筹<span class='num'>"+item.donatemoney+"</span>元</div>"
   	          		 html+="</div>"
                 
                	   html+="</a>"
                   html+="<div class='ui-btn-group'>"
                   if(item.verified=='execute'){
                       if(item.apliNum<1){
                    	   html+="<button id=css"+item.id+"  class='ui-btn' onclick='projectexecute(\""+item.id+"\")'>申请拨款</button>"
                           }else{
                        	   html+="<button class='ui-btn-lg' style='color:#cacccd'  disabled='disabled' onclick='projectexecute(\""+item.id+"\")'>申请拨款</button>"
                               }
                	   
                       }
                   if(item.verified=='expired'){
                	   if(item.apliNum<1){
                		   html+="<button id=css"+item.id+" class='ui-btn-lg' onclick='projectexpried(\""+item.id+"\")'>申请拨款/延期</button>"
                    	   }
                	   else{
                    	   html+="<button class='ui-btn-lg' style='color:#cacccd'  disabled='disabled' onclick='projectexpried(\""+item.id+"\")'>申请拨款/延期</button>"
                           }
                	   
                   }
                   if(item.verified=='pass'||item.verified=='execute'||item.verified=='expired'||item.verified=='doing'){
                  	 html+="<button class='ui-btn-lg' onclick='feedback(\""+item.id+"\")'>反馈进展</button>"
                   }
                   if(item.verified=='doing'){
                       if(item.closingverified=='none'){
                    	   html+="<button class='ui-btn-lg' onclick='projectClosing(\""+item.id+"\")'>申请结项</button>"
                           }
                       if(item.closingverified=='wait'){
                    	   html+="<button class='ui-btn-lg' onclick='projectClosing(\""+item.id+"\")'>结项审核中</button>"
                           }
                       if(item.closingverified=='refuse'){
                    	   html+="<button class='ui-btn-lg' onclick='projectClosing(\""+item.id+"\")'>修改结项报告</button>"
                           }
                       }
                   if(item.verified=='over'){
                	   html+="<button class='ui-btn-lg' onclick='projectClosing(\""+item.id+"\")'>查看结项</button>"
                       }
                   if(item.verified=='draft'||item.verified=='pass'||item.verified=='modify'){
                      if(item.projectDetail == null || item.projectDetail == ''){
                         html+="<button class='ui-btn-lg' onclick='editproject(\""+item.id+"\")'>编辑项目</button>"
                      }else{
                         html+="<button class='ui-btn-lg' disabled='disabled'>(限电脑编辑)</button>"
                      }
                   }		                            
                   if(item.verified=='draft'){
  			           html+="<button class='ui-btn-lg' onclick='deleteproject(\""+item.id+"\")'>删除项目</button>"
                   }	                            
                   html+="</div>"
                   html+="</div>"
                   html+="</div>" 
                   html+="</li>"
          
          	  });
              $("#myproject").append($(html));

              if(data.length<finalOffset){       				
   				$("#week").html("已经到底了")
   				$("#week").removeAttr("onclick");
   				
       		}else{
  	            $("#week").html("加载更多")
  	            $("#week").attr("onclick","ajaxRead()");
           		}
            },  
            complete:function(){console.log('mission complete.')} ,
            error:function(data){
          	  $("#week").html('已经到底了');
            }
           
      });  
    }
    function feedback(id){
    	window.location.href = "/scfire/project/projectFeedbackShow?projectid="+id;
    }

    function editproject(id){
    	window.location.href = "/scfire/project/edit?projectid="+id;
    }

    function deleteproject(id){
    	window.location.href = "/scfire/project/delete?id="+id+"&delopt=own";
    }

    function projectClosing(id){
    	window.location.href = "/scfire/project/createProjectCloseing?projectid="+id;
    }
    function projectexpried(id){
        $("#project").val(id);
    	$("#expried-dialog").addClass('show');
    }
    function projectexecute(id){
    	$("#project").val(id);
    	$("#execute-dialog").addClass('show');
    }
    function closeDialog(element){
    	   $("#"+element).removeClass('show');
    	}
    function closeDialogTwo(element,id){
 	   $("#"+element).removeClass('show');
 	   $("#css"+id).attr("disabled","disabled");
 	   $("#css"+id).css("color","#cacccd");
 	}
 	function expriedClick(element){
 	 	var choose = document.getElementsByName("radio");
		var type = 0 ;
		for(var i=0;i<choose.length;i++){
			if(choose[i].checked){
			 	type = i;
			 }
		 }
		 apllicationTwo(element,type);
 	 	}
    //异步加载首页内容信息
	function apllication(element){
		var id=$("#project").val();
        var html="";
        var el,e2;
        closeDialogTwo(element,id)
    	$.ajax({ 
    		data:{
		    	Id:id,
    	    } , 
            type:'get',  
            dataType:'json',
            url:'/scfire/project/applicationfund?format=json',         
            beforeSend:function(){
	            	el=$.loading({
	    		        content:"加载中...",
	    		    });
                },
            success:function(data){
                if(data[0].num==1){
                	e2=$.tips({
                        content:'申请拨款成功！请耐心等待火堆回复',
                        stayTime:2000,
                        type:"success"
                    })
                    e2.on("tips:hide",function(){
                        console.log("tips hide");
                    })
                    el.loading("hide");
                    }else{
                    	e2=$.tips({
                            content:'您的申请已近提交！请耐心等待火堆回复',
                            stayTime:2000,
                            type:"info"
                        })
                        e2.on("tips:hide",function(){
                            console.log("tips hide");
                        })
                        el.loading("hide");
                        }
            },  
            complete:function(){},
            error:function(data){
            	el.loading("hide");
            	el=$.loading({
    		        content:"申请失败,请刷新重试",
    		    });
            }
      });  
    }
	 //异步加载首页内容信息
	function apllicationTwo(element,shenq){
		var id=$("#project").val();
        var html="";
        var el,e2;
        closeDialogTwo(element,id)
    	$.ajax({ 
    		data:{
		    	Id:id,
		    	shenq:shenq,
    	    } , 
            type:'get',  
            dataType:'json',
            url:'/scfire/project/appliYanorFun?format=json',         
            beforeSend:function(){
	            	el=$.loading({
	    		        content:"加载中...",
	    		    });
                },
            success:function(data){
                if(data[0].num==1){
                	e2=$.tips({
                        content:'申请拨款成功！请耐心等待火堆回复',
                        stayTime:2000,
                        type:"success"
                    })
                    e2.on("tips:hide",function(){
                        console.log("tips hide");
                    })
                    el.loading("hide");
                    }else if(data[0].num==2){
                    	e2=$.tips({
                            content:'申请延期成功！请耐心等待火堆回复',
                            stayTime:2000,
                            type:"info"
                        })
                        e2.on("tips:hide",function(){
                            console.log("tips hide");
                        })
                        el.loading("hide");
                        }else{
                        	e2=$.tips({
                                content:'您的申请已近提交！请耐心等待火堆回复',
                                stayTime:2000,
                                type:"info"
                            })
                            e2.on("tips:hide",function(){
                                console.log("tips hide");
                            })
                            el.loading("hide");
                            }
            },  
            complete:function(){},
            error:function(data){
            	el.loading("hide");
            	el=$.loading({
    		        content:"申请失败,请刷新重试",
    		    });
            }
      });  
    }
    </script>
</body>
</html>